<template>
  <div>
    <webQuerySource @source="sourceMethod"></webQuerySource>
    <el-table :data="list" height="640" border style="width: 100%">
      <el-table-column type="index" width="80"></el-table-column>
      <el-table-column prop="tag_id" label="标签ID" width="80">
      </el-table-column>
      <el-table-column prop="tag_type" label="标签分类" width="180">
      </el-table-column>
      <el-table-column prop="tag_name" label="标签名"></el-table-column>
      <el-table-column prop="tag_source" label="来源"></el-table-column>
      <el-table-column prop="song_list_num" label="歌单数" :formatter="fmtNumMethod"></el-table-column>
      <el-table-column prop="hot_num" label="热门歌单数"></el-table-column>
      <el-table-column prop="new_num" label="最新歌单数"></el-table-column>
      <el-table-column prop="create_date" label="创建时间"></el-table-column>
    </el-table>
    <el-pagination background layout="total, prev, pager, next, jumper" :total="total" :page-size="ps" @current-change="listMethod">
    </el-pagination>
  </div>
</template>
<script>
import apis from "@utils/apis";
import webQuerySource from "@comps/cms/WebQuerySource.vue";

export default {
  data() {
    return {
      pn: 1,
      ps: 1000,
      total: 0,
      source: 'all',
      list: [],
    }
  },

  components: {
    webQuerySource,
  },

  mounted() {
    this.listMethod()
  },

  methods: {
    listMethod(page) {
      let loading = this.$loading({
        lock: true,
        text: '数据加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      this.pn = page || 1
      apis.webTagApi({
        pn: this.pn,
        ps: this.ps,
        source: this.source,
      }).then(res => {
        loading.close();
        this.total = res.result.total
        this.list = res.result.docs
      })
    },

    sourceMethod(source) {
      this.source = source
      this.listMethod()
    },

    fmtNumMethod(row, column, cellValue, index) {
      return cellValue == 0 ? (row.hot_num + row.new_num) : cellValue
    },

  }
}

</script>
